package com.bw.z.mvp.model.entity;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * {"medias":null,"news_type":0,"news_author":"string","news_value":"string","news_title":"string","news_url":"string","news_time":0,"author_id":0,"channel_id":0,"news_id":37}
 */
public class TextBannerEntity extends BaseEntity {
    public String values;

    public List<Values> getValues() {
        if (values.isEmpty())
            return null;
        List<Values> list = new ArrayList<>();
        //new Gson().fromJson(values,Values.class)
        //[{}.{}]
        try {
            JSONArray jsonArray = new JSONArray(values);
            for (int i = 0; i < jsonArray.length(); i++) {
                String item = jsonArray.getString(i);
                Values entity = new Gson().fromJson(item, Values.class);
                list.add(entity);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //为测试效果将list中数据进行复用
        for (int i = 1; i < 5; i++) {
            Values entity = list.get(0);
            list.add(entity);
        }
        return list;
    }

    public static class Values {
        public int news_type;
        public String news_author;
        public String news_value;
        public String news_title;
        public String news_url;
        public long news_time;
        public long author_id;
        public long channel_id;
        public long news_id;
    }
}
